package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.MerchantbusinessService;
import com.youi.entity.Merchantbusiness;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 商家营业信息控制层
* @author Administrator
*/
@Controller
public class MerchantbusinessController  extends HttpRequestManage{

		@Autowired
		private MerchantbusinessService merchantbusinessService;

		/**
		 * I-67
		 * 添加或编辑商家营业信息
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/addOrEditMerchantbusiness")
		public String addOrEditMerchantbusiness(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);			
			Merchantbusiness merchantbusiness=merchantbusinessService.getByParam(prams);
			if (merchantbusiness==null) {
				merchantbusiness=new Merchantbusiness();
				merchantbusiness.setMerchantId(id);
			}			
			String name=optString("name",request);
			if (name!=null){
				merchantbusiness.setName(name);
			}
			String regNo=optString("regNo",request);
			if (regNo!=null){
				merchantbusiness.setRegNo(regNo);
			}
			String address=optString("address",request);
			if (address!=null){
				merchantbusiness.setAddress(address);
			}
			String contact=optString("contact",request);
			if (contact!=null){
				merchantbusiness.setContact(contact);
			}
			String contactIdCard=optString("contactIdCard",request);
			if (contactIdCard!=null&&contactIdCard.trim().length()>0) {
				merchantbusiness.setContactIdCard(contactIdCard);
			}
			String capital=optString("capital",request);
			if (capital!=null){
				merchantbusiness.setCapital(capital);
			}
			String businessScope=optString("businessScope",request);
			if (businessScope!=null){
				merchantbusiness.setBusinessScope(businessScope);
			}
			Date gmtValidity=optDate("gmtValidity", request, "yyyy-MM-dd HH:mm:ss");
			if (gmtValidity!=null) {
				merchantbusiness.setGmtValidity(gmtValidity);
			}
			Date gmtOcCode=optDate("gmtOcCode", request, "yyyy-MM-dd HH:mm:ss");
			if (gmtOcCode!=null) {
				merchantbusiness.setGmtOcCode(gmtOcCode);
			}
			String license=optString("license",request);
			if (license!=null){
				merchantbusiness.setLicense(license);
			}
			String scCode=optString("scCode",request);
			if (scCode!=null){
				merchantbusiness.setScCode(scCode);
			}
			String taxCert=optString("taxCert",request);
			if (taxCert!=null){
				merchantbusiness.setTaxCert(taxCert);
			}
			String ocCert=optString("ocCert",request);
			if (ocCert!=null){
				merchantbusiness.setOcCert(ocCert);
			}
			Integer isOcCode=optInteger("isOcCode",request);
			if (isOcCode!=null){
				merchantbusiness.setIsOcCode(isOcCode);
			}
			String aolNo=optString("aolNo",request);
			if (aolNo!=null){
				merchantbusiness.setAolNo(aolNo);
			}
			merchantbusiness.setGmtModify(new Date());
			merchantbusinessService.saveOrUpdate(merchantbusiness);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}

		
		/**
		 * I-68
		 * 查询商家营业信息
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantbusinessById")
		public String getMerchantbusinessById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);			
			Merchantbusiness merchantbusiness=merchantbusinessService.getByParam(prams);
			if (merchantbusiness==null) {
				merchantbusiness=new Merchantbusiness();
				merchantbusiness.setMerchantId(id);
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantbusiness);//jsonObject	json对象
		}

}
